package com.example.module_d;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class Register extends AppCompatActivity implements View.OnClickListener {

    private EditText et_username;
    private EditText et_email;
    private EditText et_phone;
    private EditText et_password;
    private EditText et_repassword;
    private SharedPreferences preferences;
    private TextView tv_register;

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_register);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        et_username = findViewById(R.id.et_username);
        et_email = findViewById(R.id.et_email);
        et_phone = findViewById(R.id.et_phone);
        et_password = findViewById(R.id.et_password);
        et_repassword = findViewById(R.id.et_repassword);
        tv_register = findViewById(R.id.tv_register);
        tv_register.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);

        findViewById(R.id.tv_login).setOnClickListener(this);
        findViewById(R.id.btn_register).setOnClickListener(this);




        preferences = getSharedPreferences("config", Context.MODE_PRIVATE);
    }

    @Override
    public void onClick(View view) {
        String name = et_username.getText().toString();
        String email = et_email.getText().toString();
        String phone = et_phone.getText().toString();
        String password = et_password.getText().toString();
        String repassword = et_repassword.getText().toString();

        SharedPreferences.Editor editor = preferences.edit();
        editor.putString("name",name);
        editor.putString("email",email);
        editor.putString("phone",phone);
        editor.putString("password",password);
        editor.putString("repassword",repassword);
        editor.commit();



        if(view.getId() == R.id.btn_register) {
            Toast.makeText(this, "注册成功", Toast.LENGTH_SHORT).show();

        }

        if(view.getId() == R.id.tv_login){
            Intent intent = new Intent(Register.this,Login.class);
            startActivity(intent);
        }
    }
}